{% extends "admin/base_site.html" %}
{% load i18n admin_modify %}

{% block extrastyle %}
{% load adminmedia %}{% admin_media_prefix %}css/forms.css
<style type="text/css">
form#inventoryform input.text {
    width: 6em;
}

tr.ConfigurableProduct {
    font-style: italic;
}
</style>
{% endblock %}
{% block extrahead %}{{ block.super }}
    <script type="text/javascript">
    $(function() {
        $('#featured_on').click(function() {
           satchmo.toggle('input.featured', true);
          });
        $('#featured_off').click(function() {
           satchmo.toggle('input.featured', false)
          });
        $('#disable_all_zeroes').click(function() {
            satchmo.disable_zeroes('input.qty', 'active')
        })
        $('#disable_pv_zeroes').click(function() {
            satchmo.disable_zeroes('input.qty.ProductVariation', 'active')
        })
    });
    
    var satchmo = satchmo || {};
    satchmo.toggle = function(cls, state) {
        $(cls).each(function() { this.checked = state });
       return false;
    };
    
    satchmo.disable_zeroes = function(src, dest) {
        $(src).each(function() {
            satchmo.disable_zero(this, dest)
        });
    };
    
    satchmo.disable_zero = function(elt, dest) {
        var v = $(elt).val();
        if (v == '0') {
            dest = dest + '__';
            var id = '#' + elt.id.replace(/qty__/, dest);
            //console.log('disabling: ' + id);
            $(id)[0].checked = false;
        }
        else {
            //console.log("not disabling " + elt.id + " = " + v);
        }
    }
    </script>
{% endblock %}

{% block coltype %}colMS{% endblock %}
{% block bodyclass %}dashboard{% endblock %}
{% block userlinks %}<a href="/admin/doc/">{% trans 'Documentation' %}</a> / <a href="/admin/password_change/">{% trans 'Change password' %}</a> / <a href="/admin/logout/">{% trans 'Log out' %}</a>{% endblock %}
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
     <a href="/admin/">{% trans "Home" %}</a> &rsaquo;
     {% trans "Inventory Management" %}
</div>
{% endif %}{% endblock %}
{% block content %}
<div id="content-main">
{% if form.errors %}
    <p class="errornote">
    {% blocktrans count form.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
    </p>
{% endif %}
{% if form.fields %}
<form method="post" id="inventoryform">
    <table>
        <tr>
            <th>{% trans 'Slug' %}</th>
            <th>{% trans 'Name' %}</th>
            <th>{% trans 'Inventory' %}</th>
            <th>{% trans 'Unit Price' %}</th>
            <th>{% trans 'Active' %}</th>
            <th>{% trans 'Featured' %}</th>
        </tr>
    {% for field in form %}
        {% if field.is_hidden %}
            {{ field }}
        {% else %}
            {% ifchanged field.field.slug %}
                {% if not forloop.first %}
        		</tr>
        		{% endif %}
                <tr class="{{ field.field.subtypes }}">
                    <td><a href="/admin/product/product/{{ field.field.product_id }}/">{{ field.label_tag }}</a></td>
                    <td>{{ field.help_text}}</td>
            {% endifchanged %}
                    <td>
                	    {% if field.errors %}
                		<span class="error">{{ field.errors }}</span><br/>
        		        {% endif %}
                        {{ field }}
                    </td>
    	{% endif %}
    {% endfor %}
        		</tr>
    </table>
<input type="submit" value="Save" class="default" />
<input type="reset" value="Reset" class="default" />
<h2>{% trans 'Helpers' %}</h2>
<p><a href="#" id="featured_on">{% trans 'Mark all featured' %}</p>
<p><a href="#" id="featured_off">{% trans 'Clear all featured' %}</p>
<p><a href="#" id="disable_all_zeroes">{% trans 'Disable all Products with 0 quantity.' %}</p>
<p><a href="#" id="disable_pv_zeroes">{% trans 'Disable ProductVariations with 0 quantity.' %}</p>

</form>
{% else %}
    <p>{% trans "No inventory items." %}</p>
{% endif %}
</div>
{% endblock %}
